' ======================================================================
' 执行所有测试 case
' ======================================================================
Public Sub test_all_case()
    test_arrayToValAndIndexMap

    test_clone1DArrayAndMergeForParams_has_merge_data_pridata
    test_clone1DArrayAndMergeForParams_has_merge_data2
    test_clone1DArrayForParamVal
    test_joinElem
    test_createMultiDimensionArrayBySizeArray
    test_createMultiDimensionArray
    test_clone1DArray
    test_clone1DArrayAndMergeForParams_not_merge_data
    test_clone1DArrayAndMergeForParams_has_merge_data
    test_clone1DArrayAndMergeForParams_has_merge_data_for_maxIndex
    test_arrayCopy
    test_getArrayValueByParams
    test_getArrayValueByParams2
    test_getArrayValueByParams_obj_nothing
    test_getArrayValueByIndexArray
    test_getArrayValueByIndexArray2
    test_getArrayValueByIndexArray_obj_nothing
    test_getArrayPrimitiveValueByIndexArray
    test_getArrayObjValueByIndexArray
    test_clone1DArrayAndMergeForArray
    test_clone1DArrayAndMergeForParamsVal
    test_joinElemForParamsVal
    test_getArrayValueByParamsVal
    test_getArrayValueByParamsVal_object_nothing
    test_getArrayPrimitiveValueByParamsVal
    test_getArrayObjValueByParamsVal
    test_getArrayValueByIndexArrayForParams
    test_getArrayValueByIndexArrayForParams_obj_nothing
    test_getArrayPrimitiveValueByIndexArrayForParams
    test_getArrayObjValueByIndexArrayForParams
    test_getArrayValueByIndexArrayForParamsVal
    test_getArrayValueByIndexArrayForParamsVal_obj_nothing
    test_getArrayPrimitiveValueByIndexArrayForParamsVal
    test_getArrayObjValueByIndexArrayForParamsVal
    test_setArrayValueByParams
    test_setArrayValueByParamsVal
    test_setArrayValueByIndexArray
    test_setArrayValueByIndexArrayForParams
    test_setArrayValueByIndexArrayForParamsVal
    test_getArrayPrimitiveValueByParams_1
    test_getArrayObjValueByParams_1
End Sub

' ======================================================================
' 测试 case
' ======================================================================
Private Sub test_arrayToValAndIndexMap()
    ' 1. 创建数据
    Dim arr(5) As String
    arr(0) = "x0"
    arr(1) = "x1"
    arr(2) = "x2"
    arr(3) = "x3"
    ' 最后一个是空字符串

    ' 2. 执行测试
    Dim result As Object
    Set result = UtilsArray.arrayToValAndIndexMap(arr)

    ' 3. 检查结果
    Debug.Assert result.Count = 5
    Debug.Assert result.Exists("x0")
    Debug.Assert result.Exists("x1")
    Debug.Assert result.Exists("x2")
    Debug.Assert result.Exists("x3")
    Debug.Assert result.Exists("")
    Debug.Assert result.Exists("x4") = False

    Debug.Assert result.Item("x0") = 0
    Debug.Assert result.Item("x1") = 1
    Debug.Assert result.Item("x2") = 2
    Debug.Assert result.Item("x3") = 3
    Debug.Assert result.Item("") = 4
End Sub

Private Sub test_joinElem()
    Dim arr(3) As String
    arr(0) = "aa"
    arr(1) = "bb"
    arr(2) = "cc"
    arr(3) = "dd"
    
    Debug.Assert UtilsArray.joinElem(arr, ",") = "aa,bb,cc,dd"
End Sub

Private Sub test_createMultiDimensionArrayBySizeArray()
    Dim arr(3) As Integer
    arr(0) = 1
    arr(1) = 2
    arr(2) = 3
    arr(3) = 4
    
    Dim result As Variant
    result = UtilsArray.createMultiDimensionArrayBySizeArray(arr)
    
    Debug.Assert UBound(result) = 0
    'Debug.Print UBound(result(0)) = 1
    'Debug.Print UBound(result) = 0
    'Debug.Print UBound(result) = 0
    
End Sub

Private Sub test_createMultiDimensionArray()
    Dim result() As Variant
    result = UtilsArray.createMultiDimensionArray(3, 2)
    Debug.Assert UBound(result) = 2
    
End Sub

Private Sub test_clone1DArray()
    Dim arr(4) As Variant
    arr(0) = "1234"
    arr(1) = "abc"
    
    Dim c As Collection
    Set c = New Collection
    Set arr(3) = c
    
    Dim newArr As Variant
    newArr = UtilsArray.clone1DArray(arr)
    
    Debug.Assert LBound(newArr) = 0
    Debug.Assert UBound(newArr) = 4
    
    'Debug.Assert Not newArr Is arr
    Debug.Assert newArr(0) = "1234"
    Debug.Assert newArr(1) = "abc"
    Debug.Assert IsEmpty(newArr(2))
    Debug.Assert newArr(3) Is c
    Debug.Assert IsEmpty(newArr(4))
    
    newArr(0) = "12345"
    Debug.Assert arr(0) = "1234"
End Sub

Private Sub test_clone1DArrayAndMergeForParams_not_merge_data()
    Dim arr(4) As Variant
    arr(0) = "1234"
    arr(1) = "abc"
    
    Dim c As Collection
    Set c = New Collection
    Set arr(3) = c
    
    Dim newArr As Variant
    newArr = UtilsArray.clone1DArrayAndMergeForParams(arr)
    
    Debug.Assert LBound(newArr) = 0
    Debug.Assert UBound(newArr) = 4
    
    Debug.Assert newArr(0) = "1234"
    Debug.Assert newArr(1) = "abc"
    Debug.Assert IsEmpty(newArr(2))
    Debug.Assert newArr(3) Is c
    Debug.Assert IsEmpty(newArr(4))
    
    newArr(0) = "12345"
    Debug.Assert arr(0) = "1234"
End Sub

Private Sub test_clone1DArrayAndMergeForParams_has_merge_data()
    Dim arr(4) As Variant
    arr(0) = "1234"
    arr(1) = "abc"
    
    Dim c As Collection
    Set c = New Collection
    Set arr(3) = c
    
    Dim c2 As Collection
    Set c2 = New Collection
    
    Dim newArr As Variant
    newArr = UtilsArray.clone1DArrayAndMergeForParams( _
        arr, "xxxx", "yyy", c2, "zzz")
    
    Debug.Assert LBound(newArr) = 0
    Debug.Assert UBound(newArr) = 8
    
    Debug.Assert newArr(0) = "1234"
    Debug.Assert newArr(1) = "abc"
    Debug.Assert IsEmpty(newArr(2))
    Debug.Assert newArr(3) Is c
    Debug.Assert IsEmpty(newArr(4))
    Debug.Assert newArr(5) = "xxxx"
    Debug.Assert newArr(6) = "yyy"
    Debug.Assert newArr(7) Is c2
    Debug.Assert newArr(8) = "zzz"
    
    newArr(0) = "12345"
    Debug.Assert arr(0) = "1234"
End Sub

Private Sub test_clone1DArrayAndMergeForParams_has_merge_data_pridata()
    Dim arr(4) As Integer
    arr(0) = 1234
    arr(1) = 22
    
    Dim newArr As Variant
    newArr = UtilsArray.clone1DArrayAndMergeForParams( _
        arr, "xxxx", "yyy", "zzz")

    Debug.Assert LBound(newArr) = 0
    Debug.Assert UBound(newArr) = 7

    Debug.Assert newArr(0) = 1234
    Debug.Assert newArr(1) = 22
    Debug.Assert newArr(2) = 0
    Debug.Assert newArr(3) = 0
    Debug.Assert newArr(4) = 0
    Debug.Assert newArr(5) = "xxxx"
    Debug.Assert newArr(6) = "yyy"
    Debug.Assert newArr(7) = "zzz"

    ' 修改方法生成的结果不会影响原始数组
    newArr(0) = "12345"
    Debug.Assert arr(0) = "1234"
End Sub

Private Sub test_clone1DArrayAndMergeForParams_has_merge_data2()
    Dim arr(4) As Variant
    arr(0) = "1234"
    arr(1) = "abc"

    Dim c As Collection
    Set c = New Collection
    Set arr(3) = c

    Dim c2 As Collection
    Set c2 = New Collection

    Dim newArr As Variant
    newArr = UtilsArray.clone1DArrayAndMergeForParams( _
        arr, "xxxx", "yyy", c2, "zzz")

    Debug.Assert LBound(newArr) = 0
    Debug.Assert UBound(newArr) = 8

    Debug.Assert newArr(0) = "1234"
    Debug.Assert newArr(1) = "abc"
    Debug.Assert IsEmpty(newArr(2))
    Debug.Assert newArr(3) Is c
    Debug.Assert IsEmpty(newArr(4))
    Debug.Assert newArr(5) = "xxxx"
    Debug.Assert newArr(6) = "yyy"
    Debug.Assert newArr(7) Is c2
    Debug.Assert newArr(8) = "zzz"

    ' 修改方法生成的结果不会影响原始数组
    newArr(0) = "12345"
    Debug.Assert arr(0) = "1234"
End Sub

Private Sub test_clone1DArrayAndMergeForParams_has_merge_data_for_maxIndex()
    Dim arr1(3 To 5) As Variant
    arr1(3) = "a13"
    arr1(4) = "a14"
    arr1(5) = "a15"
    
    Dim newArr As Variant
    newArr = UtilsArray.clone1DArrayAndMergeForParams( _
        arr1, "xxxx", "yyy", "zzz")
        
    Debug.Assert LBound(newArr) = 3
    Debug.Assert UBound(newArr) = 8
    
    Debug.Assert newArr(3) = "a13"
    Debug.Assert newArr(4) = "a14"
    Debug.Assert newArr(5) = "a15"
    Debug.Assert newArr(6) = "xxxx"
    Debug.Assert newArr(7) = "yyy"
    Debug.Assert newArr(8) = "zzz"
End Sub

Private Sub test_arrayCopy()
    Dim arr(7) As Variant
    arr(0) = "v0"
    arr(1) = "v1"
    
    Dim c As Collection
    Set c = New Collection
    Set arr(3) = c
    
    arr(4) = "v4"
    arr(5) = "v5"
    arr(6) = "v6"
    arr(7) = "v7"
    
    Dim arr2(5) As Variant
    arr2(0) = "x0"
    arr2(1) = "x1"
    arr2(2) = "x2"
    arr2(3) = "x3"
    arr2(4) = "x4"
    arr2(5) = "x5"
    UtilsArray.arrayCopy arr, 1, arr2, 2, 3
    
    Debug.Assert arr2(0) = "x0"
    Debug.Assert arr2(1) = "x1"
    Debug.Assert arr2(2) = "v1"
    Debug.Assert IsEmpty(arr2(3))
    Debug.Assert arr2(4) Is c
    Debug.Assert arr2(5) = "x5"
End Sub

'============================
' getArrayValueByParams
'============================
Private Sub test_getArrayValueByParams()
    Dim arr(0 To 2, 0 To 3) As String
    arr(0, 1) = "abcd"
    arr(1, 2) = "xyz"
    
    Dim result As String
    result = UtilsArray.getArrayValueByParams(arr, 1, 2)
    Debug.Assert result = "xyz"
End Sub

Private Sub test_getArrayValueByParams2()
    Dim arr(0 To 2, 0 To 3, 0 To 4) As Variant
    arr(0, 1, 2) = "abcd"
    arr(1, 2, 3) = "xyz"
    
    Dim c1 As Collection
    Set c1 = New Collection
    c1.Add "aaaa"
    Dim c2 As Collection
    Set c2 = New Collection
    c2.Add "bbbb"

    Set arr(2, 3, 4) = c1
    Set arr(2, 3, 3) = c2
    
    Dim result As Variant
    result = UtilsArray.getArrayValueByParams(arr, 1, 2, 3)
    Debug.Assert result = "xyz"
    
    Set result = UtilsArray.getArrayValueByParams(arr, 2, 3, 4)
    Debug.Assert result Is c1
    
    Set result = UtilsArray.getArrayValueByParams(arr, 2, 3, 3)
    Debug.Assert result Is c2
End Sub

Private Sub test_getArrayValueByParams_obj_nothing()
    Dim arr(0 To 2, 0 To 3) As String

    Dim result As Collection
    
On Error GoTo catch:
    Set result = UtilsArray.getArrayValueByParams(arr, 1, 1)
    GoTo continue
catch:
    If Err.Number = 424 Then
        Set result = Nothing
    Else
        Err.Raise Err.Number, Description:=Err.Description
    End If
continue:
    
    
    Debug.Assert result Is Nothing
End Sub

'============================================
'getArrayValueByIndexArray
'============================================
Private Sub test_getArrayValueByIndexArray()
    Dim arr(0 To 2, 0 To 3) As String
    arr(0, 1) = "abcd"
    arr(1, 2) = "xyz"
    
    '
    Dim indexes(1) As Variant
    indexes(0) = 1
    indexes(1) = 2
    
    Dim result As String
    result = UtilsArray.getArrayValueByIndexArray(arr, indexes)
    Debug.Assert result = "xyz"
End Sub

Private Sub test_getArrayValueByIndexArray2()
    Dim arr(0 To 2, 0 To 3, 0 To 4) As Variant
    arr(0, 1, 2) = "abcd"
    arr(1, 2, 3) = "xyz"
    
    Dim c1 As Collection
    Set c1 = New Collection
    c1.Add "aaaa"
    Dim c2 As Collection
    Set c2 = New Collection
    c2.Add "bbbb"

    Set arr(2, 3, 4) = c1
    Set arr(2, 3, 3) = c2
    
    '----------------------
    Dim indexes1(2) As Variant
    indexes1(0) = 1
    indexes1(1) = 2
    indexes1(2) = 3
    
    Dim indexes2(2) As Variant
    indexes2(0) = 2
    indexes2(1) = 3
    indexes2(2) = 4
    
    Dim indexes3(2) As Variant
    indexes3(0) = 2
    indexes3(1) = 3
    indexes3(2) = 3
    
    '----------------------
    Dim result As Variant
    result = UtilsArray.getArrayValueByIndexArray(arr, indexes1)
    Debug.Assert result = "xyz"
    
    Set result = UtilsArray.getArrayValueByIndexArray(arr, indexes2)
    Debug.Assert result Is c1
    
    Set result = UtilsArray.getArrayValueByIndexArray(arr, indexes3)
    Debug.Assert result Is c2
End Sub

Private Sub test_getArrayValueByIndexArray_obj_nothing()
    Dim arr(0 To 2, 0 To 3) As String
    
    Dim indexes(1) As Variant
    indexes(0) = 1
    indexes(1) = 2
    
On Error GoTo catch:
    Dim result As Object
    Set result = UtilsArray.getArrayValueByIndexArray(arr, indexes)
    GoTo continue
catch:
    If Err.Number = 424 Then
        Set result = Nothing
    Else
        Err.Raise Err.Number, Description:=Err.Description
    End If
continue:

    Debug.Assert result Is Nothing
End Sub

'===========================
'getArrayPrimitiveValueByIndexArray
'===========================
Private Sub test_getArrayPrimitiveValueByIndexArray()
    Dim arr(0 To 2, 0 To 3) As Variant
    Dim indexes(1) As Variant
    indexes(0) = 1
    indexes(1) = 2
    
    Dim result As Variant
    result = UtilsArray.getArrayPrimitiveValueByIndexArray(arr, indexes)
    Debug.Assert IsEmpty(result)
    
    Dim result2 As String
    result2 = UtilsArray.getArrayPrimitiveValueByIndexArray(arr, indexes)
    Debug.Assert result2 = ""
    
    arr(0, 1) = "abcd"
    arr(1, 2) = "xyz"
    Dim result3 As String
    result = UtilsArray.getArrayPrimitiveValueByIndexArray(arr, indexes)
    Debug.Assert result = "xyz"
End Sub

'===========================
'getArrayObjValueByIndexArray
'===========================
Private Sub test_getArrayObjValueByIndexArray()
    Dim arr(0 To 2, 0 To 3) As Variant
    Dim indexes(1) As Variant
    indexes(0) = 1
    indexes(1) = 2
    
    Dim result As Variant
    Set result = UtilsArray.getArrayObjValueByIndexArray(arr, indexes)
    Debug.Assert result Is Nothing
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xyz"
    Set arr(1, 2) = c
    
    Dim cx As Collection
    Set cx = UtilsArray.getArrayObjValueByIndexArray(arr, indexes)
    Debug.Assert cx Is c
End Sub

'===========================
'clone1DArrayAndMergeForArray
'===========================
Private Sub test_clone1DArrayAndMergeForArray()
    Dim c1 As Collection
    Set c1 = New Collection
    c1.Add "c1111"
    Dim c2 As Collection
    Set c2 = New Collection
    c1.Add "c2222"
    Dim c3 As Collection
    Set c3 = New Collection
    c1.Add "c3333"
    Dim c4 As Collection
    Set c4 = New Collection
    c1.Add "c4444"
    
    Dim a1(1 To 3) As Variant
    a1(1) = "1234"
    Set a1(2) = c1
    Set a1(3) = c2
    
    Dim a2(2 To 5) As Variant
    a2(2) = "1234xyz"
    Set a2(3) = c3
    Set a2(4) = c4
    a2(5) = 456
    
    Dim result As Variant
    result = UtilsArray.clone1DArrayAndMergeForArray(a1, a2)
    
    Debug.Assert LBound(result) = 1
    Debug.Assert UBound(result) = 7
    Debug.Assert result(1) = "1234"
    Debug.Assert result(2) Is c1
    Debug.Assert result(3) Is c2
    Debug.Assert result(4) = "1234xyz"
    Debug.Assert result(5) Is c3
    Debug.Assert result(6) Is c4
    Debug.Assert result(7) = 456
    
End Sub

' ===============================================
' clone1DArrayAndMergeForParamsVal
' ===============================================
Private Sub test_clone1DArrayAndMergeForParamsVal()
    Dim c1 As Collection
    Set c1 = New Collection
    c1.Add "c111"
    Dim c2 As Collection
    Set c2 = New Collection
    c2.Add "c222"
    
    Dim arr(3 To 6) As Variant
    arr(3) = "a3"
    Set arr(4) = c1
    Set arr(5) = c2
    arr(6) = "a6"
    
    Dim result As Variant
    result = exec_clone1DArrayAndMergeForParamsVal( _
        arr, "xyz", "2345a", "yyyy")
    
    Debug.Assert LBound(result) = 3
    Debug.Assert UBound(result) = 9
    Debug.Assert result(3) = "a3"
    Debug.Assert result(4) Is c1
    Debug.Assert result(5) Is c2
    Debug.Assert result(6) = "a6"
    Debug.Assert result(7) = "xyz"
    Debug.Assert result(8) = "2345a"
    Debug.Assert result(9) = "yyyy"
End Sub
Private Function exec_clone1DArrayAndMergeForParamsVal(ByRef arr As Variant, ParamArray ps() As Variant) As Variant
    exec_clone1DArrayAndMergeForParamsVal = UtilsArray.clone1DArrayAndMergeForParamsVal(arr, ps)
End Function

' ===============================================
' joinElemForParamsVal
' ===============================================
Private Sub test_joinElemForParamsVal()
    Dim result As String
    result = exec_joinElemForParamsVal("aaa", "bbb", "", "ccc")
    Debug.Assert result = "aaa,bbb,,ccc"
End Sub
Private Function exec_joinElemForParamsVal(ParamArray ps() As Variant) As String
    exec_joinElemForParamsVal = UtilsArray.joinElemForParamsVal(ps, ",")
End Function
' ===============================================

' ===============================================
' getArrayValueByParamsVal
' ===============================================
Private Sub test_getArrayValueByParamsVal()
    Dim arr(0 To 2, 0 To 3) As String
    arr(0, 1) = "abcd"
    arr(1, 2) = "xyz"

    Dim result As String
    result = exec_getArrayValueByParamsVal(arr, 1, 2)
    Debug.Assert result = "xyz"
End Sub

Private Sub test_getArrayValueByParamsVal_object_nothing()
    Dim arr(0 To 2, 0 To 3) As String
    Dim result As Collection

On Error GoTo catch:
    Set result = exec_getArrayValueByParamsVal(arr, 1, 1)
    GoTo continue
catch:
    If Err.Number = 424 Then
        Set result = Nothing
    Else
        Err.Raise Err.Number, Description:=Err.Description
    End If
continue:

    Debug.Assert result Is Nothing
End Sub

Private Function exec_getArrayValueByParamsVal(ByRef arr As Variant, ParamArray ps() As Variant) As Variant
    exec_getArrayValueByParamsVal = UtilsArray.getArrayValueByParamsVal(arr, ps)
End Function

' ===============================================
' getArrayPrimitiveValueByParamsVal
' ===============================================
Private Sub test_getArrayPrimitiveValueByParamsVal()
    Dim arr(0 To 2, 0 To 3) As Variant
    
    Dim result1 As Variant
    result1 = exec_getArrayPrimitiveValueByParamsVal(arr, 1, 2)
    Debug.Assert IsEmpty(result1)
    
    Dim result2 As String
    result2 = exec_getArrayPrimitiveValueByParamsVal(arr, 1, 2)
    Debug.Assert result2 = ""
    
    arr(1, 2) = "xyz"
    result1 = exec_getArrayPrimitiveValueByParamsVal(arr, 1, 2)
    Debug.Assert result1 = "xyz"
End Sub

Private Function exec_getArrayPrimitiveValueByParamsVal(ByRef arr As Variant, ParamArray ps() As Variant) As Variant
    exec_getArrayPrimitiveValueByParamsVal = UtilsArray.getArrayPrimitiveValueByParamsVal(arr, ps)
End Function

' ===============================================
' getArrayObjValueByParamsVal
' ===============================================
Private Sub test_getArrayObjValueByParamsVal()
    Dim arr(0 To 2, 0 To 3) As Variant
    
    Dim result1 As Object
    Set result1 = exec_getArrayObjValueByParamsVal(arr, 1, 2)
    Debug.Assert result1 Is Nothing
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xyz"
    
    Set arr(1, 2) = c
    Dim cx As Collection
    Set cx = exec_getArrayObjValueByParamsVal(arr, 1, 2)
    Debug.Assert cx Is c
End Sub

Private Function exec_getArrayObjValueByParamsVal(ByRef arr As Variant, ParamArray ps() As Variant) As Variant
    Set exec_getArrayObjValueByParamsVal = UtilsArray.getArrayObjValueByParamsVal(arr, ps)
End Function

' ===============================================
' getArrayValueByIndexArrayForParams
' ===============================================
Private Sub test_getArrayValueByIndexArrayForParams()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    arr(2, 2, 2, 1) = "a2221"
    Dim indexes As Variant
    indexes = Array(2, 2)

    Dim result As String
    result = UtilsArray.getArrayValueByIndexArrayForParams(arr, indexes, 2, 1)
    Debug.Assert result = "a2221"
    
    '
    Dim c As Collection
    Set c = New Collection
    c.Add "xxx"
    Set arr(2, 2, 2, 4) = c
    
    Dim result2 As Collection
    Set result2 = UtilsArray.getArrayValueByIndexArrayForParams(arr, indexes, 2, 4)
    Debug.Assert result2 Is c
End Sub

Private Sub test_getArrayValueByIndexArrayForParams_obj_nothing()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    Dim indexes As Variant
    indexes = Array(2, 2)
    
On Error GoTo catch:
    Dim result As Object
    Set result = UtilsArray.getArrayValueByIndexArrayForParams(arr, indexes, 2, 1)
    GoTo continue
catch:
    If Err.Number = 424 Then
        Set result = Nothing
    Else
        Err.Raise Err.Number, Description:=Err.Description
    End If
continue:

    Debug.Assert result Is Nothing
End Sub

' ===============================================
' getArrayPrimitiveValueByIndexArrayForParams
' ===============================================
Private Sub test_getArrayPrimitiveValueByIndexArrayForParams()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    Dim indexes As Variant
    indexes = Array(2, 2)

    Dim result1 As Variant
    result1 = UtilsArray.getArrayPrimitiveValueByIndexArrayForParams(arr, indexes, 2, 1)
    Debug.Assert IsEmpty(result1)
    
    Dim result2 As String
    result2 = UtilsArray.getArrayPrimitiveValueByIndexArrayForParams(arr, indexes, 2, 1)
    Debug.Assert result1 = ""
    
    arr(2, 2, 2, 1) = "a2221"
    result1 = UtilsArray.getArrayPrimitiveValueByIndexArrayForParams(arr, indexes, 2, 1)
    Debug.Assert result1 = "a2221"

End Sub

' ===============================================
' getArrayObjValueByIndexArrayForParams
' ===============================================
Private Sub test_getArrayObjValueByIndexArrayForParams()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    Dim indexes As Variant
    indexes = Array(2, 2)

    Dim result1 As Variant
    Set result1 = UtilsArray.getArrayObjValueByIndexArrayForParams(arr, indexes, 2, 1)
    Debug.Assert result1 Is Nothing
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xyz"
    
    Set arr(2, 2, 2, 1) = c
    Set result1 = UtilsArray.getArrayObjValueByIndexArrayForParams(arr, indexes, 2, 1)
    Debug.Assert result1 Is c
End Sub

' ===============================================
' getArrayValueByIndexArrayForParamsVal
' ===============================================
Private Sub test_getArrayValueByIndexArrayForParamsVal()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    arr(2, 2, 2, 1) = "a2221"
    Dim indexes As Variant
    indexes = Array(2, 2)

    Dim result As String
    result = exec_getArrayValueByIndexArrayForParamsVal(arr, indexes, 2, 1)
    Debug.Assert result = "a2221"

    Dim c As Collection
    Set c = New Collection
    c.Add "xxx"
    Set arr(2, 2, 2, 4) = c
    
    Dim result2 As Collection
    Set result2 = exec_getArrayValueByIndexArrayForParamsVal(arr, indexes, 2, 4)
    Debug.Assert result2 Is c
End Sub

Private Function exec_getArrayValueByIndexArrayForParamsVal(ByRef arr As Variant, ByRef indexes As Variant, ParamArray ps() As Variant) As Variant
On Error GoTo catch:
    exec_getArrayValueByIndexArrayForParamsVal = UtilsArray.getArrayValueByIndexArrayForParamsVal(arr, indexes, ps)
    Exit Function
catch:
    Set exec_getArrayValueByIndexArrayForParamsVal = UtilsArray.getArrayValueByIndexArrayForParamsVal(arr, indexes, ps)
End Function


Private Sub test_getArrayValueByIndexArrayForParamsVal_obj_nothing()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    Dim indexes As Variant
    indexes = Array(2, 2)
    
    On Error GoTo catch:
        Dim result As Object
        Set result = exec_getArrayValueByIndexArrayForParamsVal(arr, indexes, 2, 1)
        GoTo continue
catch:
        If Err.Number = 424 Then
            Set result = Nothing
        Else
            Err.Raise Err.Number, Description:=Err.Description
        End If
continue:
        Debug.Assert result Is Nothing
End Sub

' ===============================================
' getArrayPrimitiveValueByIndexArrayForParamsVal
' ===============================================
Private Sub test_getArrayPrimitiveValueByIndexArrayForParamsVal()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    Dim indexes As Variant
    indexes = Array(2, 2)

    Dim result1 As Variant
    result1 = exec_getArrayPrimitiveValueByIndexArrayForParamsVal(arr, indexes, 2, 1)
    Debug.Assert IsEmpty(result1)

    Dim result2 As String
    result2 = exec_getArrayPrimitiveValueByIndexArrayForParamsVal(arr, indexes, 2, 1)
    Debug.Assert result2 = ""
    
    arr(2, 2, 2, 1) = "a2221"
    result1 = exec_getArrayPrimitiveValueByIndexArrayForParamsVal(arr, indexes, 2, 1)
    Debug.Assert result1 = "a2221"
End Sub

Private Function exec_getArrayPrimitiveValueByIndexArrayForParamsVal(ByRef arr As Variant, ByRef indexes As Variant, ParamArray ps() As Variant) As Variant
    exec_getArrayPrimitiveValueByIndexArrayForParamsVal = UtilsArray.getArrayPrimitiveValueByIndexArrayForParamsVal(arr, indexes, ps)
End Function

' ===============================================
' getArrayObjValueByIndexArrayForParamsVal
' ===============================================
Private Sub test_getArrayObjValueByIndexArrayForParamsVal()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    Dim indexes As Variant
    indexes = Array(2, 2)

    Dim result1 As Object
    Set result1 = exec_getArrayObjValueByIndexArrayForParamsVal(arr, indexes, 2, 1)
    Debug.Assert result1 Is Nothing

    Dim c As Collection
    Set c = New Collection
    c.Add "xyz"
    Set arr(2, 2, 2, 1) = c
    
    Dim cx As Collection
    Set cx = exec_getArrayObjValueByIndexArrayForParamsVal(arr, indexes, 2, 1)
    Debug.Assert cx Is c
End Sub

Private Function exec_getArrayObjValueByIndexArrayForParamsVal(ByRef arr As Variant, ByRef indexes As Variant, ParamArray ps() As Variant) As Variant
    Set exec_getArrayObjValueByIndexArrayForParamsVal = UtilsArray.getArrayObjValueByIndexArrayForParamsVal(arr, indexes, ps)
End Function

' ===============================================
' clone1DArrayForParamVal
' ===============================================
Private Sub test_clone1DArrayForParamVal()
    Dim c1 As Collection
    Set c1 = New Collection
    c1.Add "xyz"
    
    Dim c2 As Collection
    Set c2 = New Collection
    c2.Add "abc"

    Dim arr As Variant
    arr = exec_clone1DArrayForParamVal(2, 3, c1, 5, c2, 6)

    Debug.Assert arr(0) = 2
    Debug.Assert arr(1) = 3
    Debug.Assert arr(2) Is c1
    Debug.Assert arr(3) = 5
    Debug.Assert arr(4) Is c2
    Debug.Assert arr(5) = 6
End Sub

Private Function exec_clone1DArrayForParamVal(ParamArray ps() As Variant) As Variant
    exec_clone1DArrayForParamVal = UtilsArray.clone1DArrayForParamVal(ps)
End Function

' ===============================================
' setArrayValueByParams
' ===============================================
Private Sub test_setArrayValueByParams()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant

    UtilsArray.setArrayValueByParams "abc", arr, 1, 2, 3, 4
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 4) = "abc"
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xxxx"
    UtilsArray.setArrayValueByParams c, arr, 1, 2, 3, 2
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 2) Is c
    
End Sub

' ===============================================
' setArrayValueByParamsVal
' ===============================================
Private Sub test_setArrayValueByParamsVal()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant

    exec_setArrayValueByParamsVal "abc", arr, 1, 2, 3, 4
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 4) = "abc"
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xxxx"
    exec_setArrayValueByParamsVal c, arr, 1, 2, 3, 2
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 2) Is c
End Sub

Private Sub exec_setArrayValueByParamsVal(ByRef val As Variant, ByRef arr As Variant, ParamArray indexes() As Variant)
    UtilsArray.setArrayValueByParamsVal val, arr, indexes
End Sub

' ===============================================
' setArrayValueByIndexArray
' ===============================================
Private Sub test_setArrayValueByIndexArray()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant

    UtilsArray.setArrayValueByIndexArray "abc", arr, Array(1, 2, 3, 4)
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 4) = "abc"
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xxxx"
    UtilsArray.setArrayValueByIndexArray c, arr, Array(1, 2, 3, 2)
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 2) Is c
End Sub

' ===============================================
' setArrayValueByIndexArrayForParams
' ===============================================
Private Sub test_setArrayValueByIndexArrayForParams()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant

    UtilsArray.setArrayValueByIndexArrayForParams "abc", arr, Array(1, 2), 3, 4
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 4) = "abc"
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xxxx"
    UtilsArray.setArrayValueByIndexArrayForParams c, arr, Array(1, 2), 3, 2
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 2) Is c
End Sub

' ===============================================
' setArrayValueByIndexArrayForParamsVal
' ===============================================
Private Sub test_setArrayValueByIndexArrayForParamsVal()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant

    exec_setArrayValueByIndexArrayForParamsVal "abc", arr, Array(1, 2), 3, 4
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 4) = "abc"
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xxxx"
    exec_setArrayValueByIndexArrayForParamsVal c, arr, Array(1, 2), 3, 2
    Debug.Assert UtilsArray.getArrayValueByParams(arr, 1, 2, 3, 2) Is c
End Sub

Private Sub exec_setArrayValueByIndexArrayForParamsVal(ByRef val As Variant, ByRef arr As Variant, ByRef indexes As Variant, ParamArray ps() As Variant)
    UtilsArray.setArrayValueByIndexArrayForParamsVal val, arr, indexes, ps
End Sub

'=================================================
'getArrayPrimitiveValueByParams
'=================================================
Private Sub test_getArrayPrimitiveValueByParams_1()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    
    Dim a As Variant
    a = UtilsArray.getArrayPrimitiveValueByParams(arr, 1, 2, 3, 4)
    Debug.Assert IsEmpty(a)
    
    Dim b As String
    b = UtilsArray.getArrayPrimitiveValueByParams(arr, 1, 2, 3, 4)
    Debug.Assert IsEmpty(b) = False
    Debug.Assert b = ""
    
    Dim c As Integer
    c = UtilsArray.getArrayPrimitiveValueByParams(arr, 1, 2, 3, 4)
    Debug.Assert IsEmpty(c) = False
    Debug.Assert c = 0
    
    Dim d As Integer
    d = UtilsArray.getArrayPrimitiveValueByParams(arr, 1, 2, 3, 4)
    Debug.Assert IsEmpty(d) = False
    Debug.Assert d = 0
    
    UtilsArray.setArrayValueByParams "xyz", arr, 1, 2, 3, 4
    a = UtilsArray.getArrayPrimitiveValueByParams(arr, 1, 2, 3, 4)
    Debug.Assert a = "xyz"

End Sub


'=================================================
'getArrayObjValueByParams
'=================================================
Private Sub test_getArrayObjValueByParams_1()
    Dim arr(1 To 4, 1 To 4, 1 To 4, 1 To 4) As Variant
    
    Dim a As Object
    Set a = UtilsArray.getArrayObjValueByParams(arr, 1, 2, 3, 4)
    Debug.Assert a Is Nothing
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xyz"
    UtilsArray.setArrayValueByParams c, arr, 1, 2, 3, 4
    
    Dim c1 As Collection
    Set c1 = UtilsArray.getArrayObjValueByParams(arr, 1, 2, 3, 4)
    Debug.Assert c1 Is c
End Sub
